package com.guigu.www.tangyingmeng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.www.mapper.*;
import com.guigu.www.pojo.*;
import com.guigu.www.tangyingmeng.service.TymInterventionTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class TymInterventionTemplateServiceImpl implements TymInterventionTemplateService {

    @Autowired
    private InterventionTemplateMapper templateMapper;
    @Autowired
    private TemplateWholesomeMapper wholesomeMapper;
    @Autowired
    private KeepZongMapper keepZongMapper;
    @Autowired
    private FoodZongMapper foodZongMapper;

    //分页查询所有模板
    @Override
    public PageVo<InterventionTemplate> seltemplateall(Map<String, String> map) {
        QueryWrapper<InterventionTemplate> wrapper = new QueryWrapper<>();
        wrapper.like("inter_temp_id",map.get("findid")).like("inter_temp_title", map.get("findname"));
        IPage<InterventionTemplate> page = new Page<>(Integer.valueOf(map.get("index")), Integer.valueOf(map.get("pageSize")));
        page = templateMapper.selectPage(page, wrapper);
        PageVo<InterventionTemplate> pageVo = new PageVo<>();
        pageVo.setTotal(page.getTotal());
        pageVo.setRows(page.getRecords());
        return pageVo;
    }

    //查询所有健康方案
    @Override
    public List<TemplateWholesome> selwholesomeall() {
        QueryWrapper<TemplateWholesome> wrapper = new QueryWrapper<>();
        wrapper.eq("temp_who_state",0);
        List<TemplateWholesome> list = wholesomeMapper.selectList(wrapper);
        return list;
    }

    //查询所有膳食方案
    @Override
    public List<FoodZong> selfoodall() {
        QueryWrapper<FoodZong> wrapper = new QueryWrapper<>();
        wrapper.eq("food_zong_state",0);
        List<FoodZong> list = foodZongMapper.selectList(wrapper);
        return list;
    }

    //查询所有运动方案
    @Override
    public List<KeepZong> selkeepall() {
        QueryWrapper<KeepZong> wrapper = new QueryWrapper<>();
        wrapper.eq("keep_zong_state",0);
        List<KeepZong> list = keepZongMapper.selectList(wrapper);
        return list;
    }

    //禁用
    @Override
    public Boolean jing(Integer id) {
        InterventionTemplate template = new InterventionTemplate();
        template.setInterTempId(id);
        template.setInterTempState(1);
        int update = templateMapper.updateById(template);
        if(update>0){
            return true;
        }else {
            return false;
        }
    }

    //启用
    @Override
    public Boolean qi(Integer id) {
        InterventionTemplate template = new InterventionTemplate();
        template.setInterTempId(id);
        template.setInterTempState(0);
        int update = templateMapper.updateById(template);
        if(update>0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean addtemplate(InterventionTemplate template) {
        template.setInterTempState(0);
        int insert = templateMapper.insert(template);
        if(insert>0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean uptemplate(InterventionTemplate template) {
        int insert = templateMapper.updateById(template);
        if(insert>0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public InterventionTemplate seltemplateone(Integer id) {
        InterventionTemplate template = templateMapper.selectById(id);
        return template;
    }

    @Override
    public Boolean deltemplate(Integer id) {
        int delete = templateMapper.deleteById(id);
        if(delete>0){
            return true;
        }else {
            return false;
        }
    }
}
